import unittest
from api.department import DepartmentAPI
from utils import common_assert
import json

class TestDepartment(unittest.TestCase):
    department_id = None

    def setUp(self):
        self.department_api = DepartmentAPI()

    def test01_add_department(self):
        add_department_data = {"name": "技术部",
                               "code": "00212",
                               "manager": "张三",
                               "introduce": "这是技术部门",
                               "pid": None}
        response = self.department_api.add_department(add_department_data)
        common_assert(self, response, 200, True, 10000, "操作成功")
        TestDepartment.department_id = response.json().get("data").get("id")
        print(TestDepartment.department_id)

    def test02_get_department(self):
        response = self.department_api.get_department(TestDepartment.department_id)
        print(response.json())
        common_assert(self, response, 200, True, 10000, "操作成功")

    def test03_update_department(self):
        update_data = {"name": "销售部"}
        response = self.department_api.update_department(TestDepartment.department_id, update_data)
        print(response.json())
        common_assert(self, response, 200, True, 10000, "操作成功")

    def test04_delete_department(self):
        response = self.department_api.delete_department(TestDepartment.department_id)
        print(response.json())
        common_assert(self, response, 200, True, 10000, "操作成功")